package com.wy2.controller;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wy2.entity.Role;
import com.wy2.entity.User;
import com.wy2.service.RoleService;
import com.wy2.util.FenyeUtil;

@RestController
@RequestMapping("/role")
@CrossOrigin
public class RoleController {

	@Autowired
	private RoleService rs;
	/**
	 * 获取全部
	 * @param fenye
	 * @param role
	 * @return
	 */
	@RequestMapping("/all")
	public FenyeUtil<Role> getAll( FenyeUtil<Role> fenye,Role role){
		fenye.setT(role);
		fenye = rs.getAll(fenye);
		
		return fenye;
		
	}
	
	/**
	 * 添加
	 * @param role
	 * @return
	 */
	@RequestMapping("/add")
	public Integer addUser(Role role) {
		//自动添加id
		UUID.randomUUID().toString();
		role.setRid(UUID.randomUUID().toString());
		
		
		return rs.addRole(role);
		
	}
	/**
	 * 修改
	 * @param role
	 * @return
	 */
	@RequestMapping("/upd")
	public Integer updUser(Role role) {
		return rs.updRole(role);
		
	}
	/**
	 * 删除
	 * @param rid
	 * @return
	 */
	@RequestMapping("/del")
	public Integer delUser(String rid) {
		return rs.delRole(rid);
	}
/**
 * 查找所有角色
 * @return
 */
	@RequestMapping("/find")
	public List<Role> find(){
		List<Role> r = rs.findAllRole();
		System.out.println("/"+r);
		return r;
	}
	/**
	 * 获取全部
	 * @return
	 */
	@RequestMapping("/getRole")
	public List<Role> getAll(){
		return rs.getRole();
	}
	
//	@RequestMapping("/getUsersRole")
//	public Object getUsersRole(String uid){
//		return rs.getUsersRole(uid);
//	}
//角色名唯一
	@RequestMapping("/select")
	public Integer getRoleRname( String rname) {
		
			
			List<Role> tlist = rs.findRname(rname);
			
			if( null != tlist && tlist.size() >0) {
				return 1;
			}else {
				return 0;
			
			
		}	
	}
	
	/**
	 * 穿梭框查詢所有角色
	 * @return
	 */
	@RequestMapping("/GetRolesAll")
	public List<Role> getRole(){
		return rs.findAll();
	}
	/**
	 * 显示所拥有的角色
	 * @param uid
	 * @return
	 */
	@RequestMapping("/getUserRole")
	public Object getUid(String uid) {
		return rs.getUserRole(uid);
		
	}
	
}
